This study investigated the efficiency of membrane polyetheretherketone/polyetherimide modified with magnesium oxide nanoparticles to remove xylene and toluene from the air with gas chromatography. The influence of effective parameters such as sorbent dosage, extraction time, and extraction temperature of the sample was investigated and the optimum conditions were chosen. Various techniques including FT-IR, XRD, EDX, and SEM, were used to characterize this membrane. To optimize adsorption efficiency, factors such as xylene and toluene concentration, adsorbent dosage, temperature, and contact time were carefully fine-tuned. It was found that 50 mg of membranes has the best adsorption efficiency for both pollutants. The maximum adsorption capacities were found to be 163 mg/g for xylene and 200 mg/g for toluene on the PEEK/PEI nanocomposite adsorbent. Moreover, 190 mg/g for xylene and 230 mg/g for toluene were observed on the PEEK/PEI membrane modified with MgO nanoparticles. These results clearly demonstrate that PEEK/PEI membrane modified with MgO nanoparticles is a highly efficient adsorbent for eliminating xylene and toluene from air, making it a promising solution for air quality purification and environmental remediation applications.